﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace QuailDashboard.View.Models
{
    public class FilterModel : Model
    {
        private bool _filterFailed, _filterWarning, _filterPassed, _filterPending, _filterAsyncPending, _filterFailedYSOD, _filterFailedTimeout, _filterFailedThirdParty, _filterFailedQuail, _filterFailedSync;
        private string _filterString;

        public event EventHandler FilterChanged;

        /// <summary>
        /// Gets or sets a value indicating whether to filter failed records
        /// </summary>
        public bool FilterFailed
        {
            get
            {
                return _filterFailed;
            }

            set
            {
                if (_filterFailed != value)
                {
                    _filterFailed = value;
                    NotifyPropertyChanged("FilterFailed");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to filter YSOD records
        /// </summary>
        public bool FilterFailedYSOD
        {
            get
            {
                return _filterFailedYSOD;
            }

            set
            {
                if (_filterFailedYSOD != value)
                {
                    _filterFailedYSOD = value;
                    NotifyPropertyChanged("FilterFailedYSOD");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to filter timeout failure records
        /// </summary>
        public bool FilterFailedTimeout
        {
            get
            {
                return _filterFailedTimeout;
            }

            set
            {
                if (_filterFailedTimeout != value)
                {
                    _filterFailedTimeout = value;
                    NotifyPropertyChanged("FilterFailedTimeout");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to filter Sync failure records
        /// </summary>
        public bool FilterFailedSync
        {
            get
            {
                return _filterFailedSync;
            }

            set
            {
                if (_filterFailedSync != value)
                {
                    _filterFailedSync = value;
                    NotifyPropertyChanged("FilterFailedSync");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to filter Quail records
        /// </summary>
        public bool FilterFailedQuail
        {
            get
            {
                return _filterFailedQuail;
            }

            set
            {
                if (_filterFailedQuail != value)
                {
                    _filterFailedQuail = value;
                    NotifyPropertyChanged("FilterFailedQuail");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to filter Third Party failure records
        /// </summary>
        public bool FilterFailedThirdParty
        {
            get
            {
                return _filterFailedThirdParty;
            }

            set
            {
                if (_filterFailedThirdParty != value)
                {
                    _filterFailedThirdParty = value;
                    NotifyPropertyChanged("FilterFailedThirdParty");
                    FireFilterChanged();
                }
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether to filter passed records
        /// </summary>
        public bool FilterPassed
        {
            get
            {
                return _filterPassed;
            }

            set
            {
                if (_filterPassed != value)
                {
                    _filterPassed = value;
                    NotifyPropertyChanged("FilterPassed");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to filter warning records
        /// </summary>
        public bool FilterWarning
        {
            get
            {
                return _filterWarning;
            }

            set
            {
                if (_filterWarning != value)
                {
                    _filterWarning = value;
                    NotifyPropertyChanged("FilterWarning");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets a value indicating whether to filter pending records
        /// </summary>
        public bool FilterPending
        {
            get
            {
                return _filterPending;
            }

            set
            {
                if (_filterPending != value)
                {
                    _filterPending = value;
                    NotifyPropertyChanged("FilterPending");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Get/set Async Pending record filter
        /// </summary>
        public bool FilterAsyncPending
        {
            get { return _filterAsyncPending; }
            set
            {
                if(_filterAsyncPending != value)
                {
                    _filterAsyncPending = value;
                    NotifyPropertyChanged("FilterAsyncPending");
                    FireFilterChanged();
                }
            }
        }

        /// <summary>
        /// Gets or sets the filter string
        /// </summary>
        public string FilterString
        {
            get
            {
                return _filterString;
            }

            set
            {
                _filterString = value == null ? null : value.Replace(" ", string.Empty);
                NotifyPropertyChanged("FilterString");
                FireFilterChanged();
            }
        }

        private void FireFilterChanged()
        {
            if (FilterChanged != null)
            {
                FilterChanged(this, EventArgs.Empty);
                NotifyPropertyChanged("FilteredTestCount");
            }
        }
    }
}
